from db import db
import datetime

class Video(db.Model):
    __tablename__ = 'video'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(255), nullable=False)
    cover = db.Column(db.String(255), nullable=False)
    video_src = db.Column(db.String(255), nullable=False)
    username = db.Column(db.String(255), nullable=False)
    introduction = db.Column(db.String(255), nullable=False)
    view = db.Column(db.Integer, nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    def __init__(self,title,cover,videoSrc,username,introduction):
        self.title = title
        self.cover = cover
        self.video_src = videoSrc
        self.username = username
        self.introduction = introduction
        self.view = 0
    
    def to_dict(self):
        return {
            'id': self.id,
            'title': self.title,
            'cover':  self.cover,
            'videoSrc': self.video_src,
            'username': self.username,
            'introduction': self.introduction,
            'view': self.view,
            'createTime': self.create_time
        }